package net.lab1024.smartadmin.module.business.payment.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.payment.dao.PaymentDao;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentAddDTO;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentUpdateDTO;
import net.lab1024.smartadmin.module.business.payment.domain.dto.PaymentQueryDTO;
import net.lab1024.smartadmin.module.business.payment.domain.entity.PaymentEntity;
import net.lab1024.smartadmin.module.business.payment.domain.vo.PaymentVO;
import net.lab1024.smartadmin.module.business.payment.domain.vo.PaymentExcelVO;
import net.lab1024.smartadmin.util.SmartPageUtil;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [  ]
 *
 * @author mrmf
 * @version 1.0
 * @company ${company}
 * @copyright (c)  ${company}Inc. All rights reserved.
 * @date 2021-05-24 19:48:52
 * @since JDK1.8
 */
@Service
public class PaymentService {

    @Autowired
    private PaymentDao paymentDao;

    /**
     * 根据id查询
     */
    public PaymentEntity getById(Long id){
        return  paymentDao.selectById(id);
    }

    /**
     * 分页查询
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    public ResponseDTO<PageResultDTO<PaymentVO>> queryByPage(PaymentQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<PaymentVO> voList = paymentDao.queryByPage(page, queryDTO);
        PageResultDTO<PaymentVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    public ResponseDTO<String> add(PaymentAddDTO addDTO) {
        PaymentEntity entity = SmartBeanUtil.copy(addDTO, PaymentEntity.class);
        paymentDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(PaymentUpdateDTO updateDTO) {
        PaymentEntity entity = SmartBeanUtil.copy(updateDTO, PaymentEntity.class);
        paymentDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        paymentDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    public List<PaymentExcelVO> queryAllExportData(PaymentQueryDTO queryDTO) {
        return paymentDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author mrmf
     * @date 2021-05-24 19:48:52
     */
    public List<PaymentExcelVO> queryBatchExportData(List<Long> idList) {
        return paymentDao.queryBatchExportData(idList);
    }
}
